package com.leimo;

import com.leimo.model.Mseeage;
import com.leimo.util.ObjectUtil;
import com.leimo.util.RedisUtils;

import java.io.IOException;

/**
 * @author 夏智峰
 * @create 2018-02-07 17:16
 */
public class TestRedisQueue {
  public static byte[] redisKey = "key".getBytes();

  static {
    try {
      init();

    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  public static void main(String[] args) {
    try {
      pop();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private static void init() throws IOException {
    for (int i = 0; i < 100; i++) {
      Mseeage mseeage = new Mseeage(i, "这是第[" + i + "]个内容");
      RedisUtils.lpush(redisKey, ObjectUtil.objectToBytes(mseeage));
    }
  }

  private static void pop() throws Exception {
    byte[] bytes = RedisUtils.rpop(redisKey);
    Mseeage mseeage = (Mseeage) ObjectUtil.bytesToObject(bytes);
    if (mseeage != null) {
      System.out.println(mseeage.getId() + "----" + mseeage.getCoontent());
    }
  }
}
